package org.phantom.demo.search.queuetest;

import java.util.concurrent.PriorityBlockingQueue;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.stereotype.Component;

@Component
public class Scanner implements Runnable {

	@Resource
	private TaskQueue<DataLevel> taskQueue = null;
	@Resource
	private ThreadPool pool = null;

	@Override
	public void run() {
		while (true) {
				PriorityBlockingQueue<DataLevel> queue = taskQueue.getQueue();
				if(!queue.isEmpty())
					pool.exec(queue);
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
		}
	}

	@PostConstruct
	public void init() {
		new Thread(this).start();
	}
}
